/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package org.sbbs.admin.mbean.sysorg;

import jakarta.annotation.PostConstruct;
import jakarta.inject.Named;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.omnifaces.cdi.ViewScoped;
import org.primefaces.model.LazyDefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.sbbs.admin.dao.SysOrgRepo;
import org.sbbs.admin.entity.SysOrg;
import org.sbbs.admin.manager.SysOrgManager;
import org.sbbs.base.jsf.BaseTreeMBean;

/**
 *
 * @author jenkins
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Named("sysOrgMBean")
@ViewScoped
public class SysOrgMBean extends BaseTreeMBean<SysOrg, Long, SysOrgRepo, SysOrgManager> {

    private static SysOrgManager staticManager;

    public SysOrgMBean(SysOrgManager m) {
        super(m);
        SysOrgMBean.staticManager = m;
    }

    @PostConstruct
    public void init() {
        this.setRoot(this.initRoot());
    }

    @Override
    protected TreeNode initNode(SysOrg r) {
        return new LazyDefaultTreeNode<>(r,
                s -> staticManager.findChildren(s),
                s -> s.isLeaf());
    }

}
